package 多线程.线程饿死;

import java.util.Scanner;

public class Hungry {
    public static void main(String[] args) throws InterruptedException{
        Object object = new Object();
        Object object2 = new Object();

        Thread t1 = new Thread(() ->{
           synchronized(object){
               try {
                   System.out.println("开始前");
                   object.wait();
                   System.out.println("开始后");
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });

        Thread t2 = new Thread(() ->{
           Scanner sc = new Scanner(System.in);
            synchronized(object){
                System.out.println("唤醒前");
                sc.next();
                object.notify();
                System.out.println("唤醒后");
            }
        });
        t2.start();
        t1.start();
    }
}
